package com.singzi.leetcode.N1900;

public class T1816 {

    public static void main(String[] args) {
        Solution1816 solution1816 = new Solution1816();
        String s = "Hello how are you Contestant";
        int k = 4;
        System.out.println(solution1816.truncateSentence(s, 5));
    }
}
class Solution1816 {
    public String truncateSentence(String s, int k) {

        StringBuilder result = new StringBuilder();

        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i) == ' ') count++;
            if(count == k) break;
            result.append(s.charAt(i));
        }



        return result.toString();

    }
}